﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Text;
using System.Web.Mvc;
namespace RedSand.Site
{
    public static class UrlUtils
    {
        public static string ToUrlString(this object input)
        {
            if (input == null) return string.Empty;

            Regex regex = new Regex("\\p{IsCombiningDiacriticalMarks}+");
            string temp = input.ToString().Normalize(NormalizationForm.FormD);
            temp = regex.Replace(temp, string.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D').Trim();
            temp = temp.Replace(' ', '-').Replace('.', '-').Replace(',', '-').Replace("\"", "").Replace("--", "-");

            regex = new Regex(@"#|%|\+|\*|\.|\\|/|>|<|\?|:|\&");
            return regex.Replace(temp, string.Empty).ToLower();
        }
        public static string ToKeyWordString(this object input)
        {
            if (input == null) return string.Empty;
            Regex regex = new Regex(@"#|%|\+|\*|\.|\\|/|>|<|\?|:|\&");
            return regex.Replace(input.ToString(), string.Empty).Replace("\"", "").Trim().ToLower();
        }
    }
}